<template>
  <div>
    <!-- 搜索 -->
    <TopFilter
      ref="commonTopFilter"
      :list="topFilterInit"
      :cols="3"
      labelWidth="100"
      @filterChange="changeHandle"
      @onCollapse="collapseHandle"
      @resetChange="resetHandle"
    ></TopFilter>
    <!-- 按钮 -->

    <!-- table -->
    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :isSelectColumn="false"
      :datakey="'records'"
      columnsRef="notification_maintain_index_01"
      :onColumnsChange="columns => (this.columns = columns)"
    >
    </FilterTable>
    <!-- 新增窗口 -->
    <Drawer
      :visible.sync="visibleDrawer3"
      :title="title"
      :width="920"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <newlyAdded v-model="initData" :row="row" :type="type" @close="infoClose" />
    </Drawer>
    <BaseDialog :visible.sync="selectDelearFlag" title="服务中心选择" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <DealerList @close="Delearclose" @save="Delearsave" selectionType="multiple" />
    </BaseDialog>
  </div>
</template>

<script>
import { getMileagechange} from '@/api/customerRepair/vehicleOwnerManagement/vehicleMileageChange/index';
import newlyAdded from './newlyAdded';
import DealerList from '@/pages/claimDemage/tools/DealerList.vue';
import { dictionary } from '@/utils/dictMixin';
import { authority } from '@/utils/authMixin';
export default {
  name: "index",
  mixins: [authority, dictionary],
  components: {
    DealerList,
    newlyAdded
  },
  data() {
    return {
      topFilterInit: this.topFilterInitFun(),
      columns: this.creatHeader(),
      fetchApi: getMileagechange, //api 接口 table请求数据入口
      fetchParams: {isCms:1},
      initData: {},
      selectDelearFlag: false,
      selectDealerData: [],
      searchDealerCode:[],
      dealerData: [],
      row:{},
      type:'',
      visibleAdd:false,
      visibleDrawer3:false,
      title:''
    };
  },
  methods: {
    topFilterInitFun() {
      return [
        {type: 'INPUT', label: 'VIN', fieldName: 'vin', placeholder: '请输入', initialValue: ''},
        {type: 'SELECT', label: '申请状态', fieldName: 'state', placeholder: '请输入', initialValue: '', itemList: this.createDictList('5569',[55691001,55691005])},
        {type: 'RANGE_DATE', label: '申请日期', fieldName: 'createdAtDateFrom|createdAtDateTo', placeholder: '请输入', initialValue: ''},
        {
          type: 'INPUT',
          label: '申请服务站',
          render: (p) => {
            return (
              <div>
                <el-select v-model={this.selectDealerData} disabled={true} multiple placeholder="请选择">
                  {this.dealerData.map((item) => (
                    <el-option key={item.dealerCode} label={item.dealerShortname} value={item.dealerCompanyCode} />
                  ))}
                </el-select>
                <multiuse-button style="position: absolute;right: 0;height:100%" icon="el-icon-search" onClick={() => this.selectDelearFlag = true} />
              </div>
            );
          },
        }
      ];
    },
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 50,
          sorter: true,
          fixed: 'left',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 120,
          render: props => {
            let istg = props.row.state == '55691002'? false : true;
            return (
              <div style="text-align:center">
                <el-button size="mini" type="text" disabled={istg} onClick={() => this.editOrdetail('edit', props.row)}>
                  审核
                </el-button>
                <el-button size="mini" type="text" onClick={() => this.editOrdetail('detail', props.row)}>
                  查看
                </el-button>
              </div>
            );
          }
        },
        {title: '申请状态', dataIndex: 'state', sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.state, '5569')}</span>;
          }},
        {title: '申请单号', dataIndex: 'mileageChangeNo', sorter: true},
        {title: 'VIN', dataIndex: 'vin', sorter: true},
        {title: '原里程', dataIndex: 'oldMileage', sorter: true},
        {title: '变更里程', dataIndex: 'newMileage', sorter: true},
        {title: '申请时间', dataIndex: 'createdAt', sorter: true,dateFormat: 'yyyy-MM-dd HH:mm'},
        {title: '审核时间', dataIndex: 'checkData', sorter: true,dateFormat: 'yyyy-MM-dd HH:mm'},
        {title: '申请服务站', dataIndex: 'dealerName', sorter: true},
        {title: '申请人', dataIndex: 'createdBy', sorter: true},
        {title: '审核人', dataIndex: 'checkBy', sorter: true},
        {title: '审核意见', dataIndex: 'checkOpinion', sorter: true}
      ];
    },
    infoClose(rData) {
      this.visibleDrawer3 = false;
      if (rData.type === 'refresh') {
        // 重新加载
        this.fetchParams = {...this.fetchParams};
      }
    },
    Delearclose() {
      this.selectDelearFlag = false;
    },
    Delearsave(obj) {
      console.log('选择数据传递', obj);
      this.dealerData = obj;
      this.selectDealerData = [];
      obj.forEach(item => {
        this.selectDealerData.push(item.dealerCompanyCode);
        this.searchDealerCode.push(item.dealerCode);
      });
      this.selectDelearFlag = false;
    },
    editOrdetail(type,val) {
      this.title = type == 'edit'?'里程变更审核':'里程变更明细';
      this.row = val;
      this.type = type;
      this.visibleDrawer3 = true;
    },
    changeHandle(val) {
      console.log('搜索的参数：', val,this.searchDealerCode);
      this.fetchParams = Object.assign({},this.fetchParams, val,{dealerCompanyCode: this.searchDealerCode.length ? this.searchDealerCode : null});
    },
    resetHandle(val) {
      this.dealerData = [];
      this.selectDealerData = [];
      this.searchDealerCode = [];
      this.fetchParams = Object.assign({}, this.fetchParams, val, { dealerCompanyCode: null }, { xhrAbort: false });
    },
    collapseHandle() {

    }
  }
}
</script>

<style scoped>

</style>
